#include "entertainment.h"
#include <malloc.h>
#include <memory.h>


#define RESIZE(arr, delta)												\
	arr.elements = realloc(arr.elements,								\
				   sizeof(arr.elements[0]) * (arr.count + delta));		\
	if (buf == NULL)													\
	{																	\
		mtm_error(err_OutOfMemory);										\
		return RES_FATAL;												\
	}																	\
	arr->count += delta;

#define SHIFT_DOWN(arr)													\
	if (i + 1 < arr.count)												\
	{																	\
		memmove(&arr.elements[i],										\
				&arr.elements[i+1],										\
				sizeof(arr.elements[0]) * (arr.count - i - 1));			\
	}


int find_movie(const char * name)
{
}

int find_game(const char * name)
{
}

int find_playlist(const char * name)
{
}

/****************************************************************************
 * ADD APPLICATION
 ***************************************************************************/

result_t cmd_add_app(FILE * outstream, const char ** args)
{
	int i;
	char * type = args[0];
	char * name = args[1];
	
	if (strcmp(type, "Movie") == 0)
	{
		if (find_movie(name) != -1)
		{
			mtm_error(err_AppExists);
			return RES_ERROR;
		}
		i = movies_arr.count;
		RESIZE(movies_arr, 1);
		strcpy(movies_arr.elements[i].name, name);
		movies_arr.elements[i].year = 0;
		strcpy(movies_arr.elements[i].type, "General");
	}
}


/****************************************************************************
 * REMOVE APPLICATION
 ***************************************************************************/

result_t cmd_rem_app(FILE * outstream, const char ** args)
{
	int i;
	char * type = args[0];
	char * name = args[1];
	
	if (strcmp(type, "Movie") == 0)
	{
		i = find_movie(name);
		if (i == -1)
		{
			mtm_error(err_AppNotExists);
			return RES_ERROR;
		}
		SHIFT_DOWN(movies_arr);
		RESIZE(movies_arr, -1);
	}
}

result_t cmd_rem_movie(FILE * outstream, const char * name)
{
}

result_t cmd_rem_playlist(FILE * outstream, const char * name)
{
}

result_t cmd_rem_game(FILE * outstream, const char * name)
{
}

/****************************************************************************
 * ADD DETAILS
 ***************************************************************************/

result_t cmd_edit_app(FILE * outstream, const char ** args)
{
}

result_t cmd_edit_movie(FILE * outstream, int index, int year, int type)
{
}

result_t cmd_edit_playlist(FILE * outstream, int index, int count, 
						   const char * type)
{
}

result_t cmd_edit_game(FILE * outstream, int index, int start, int end)
{
}

/****************************************************************************
 * USED APPLICATION
 ***************************************************************************/

cmd_usage(FILE * outstream, const char ** args)
{
}

/****************************************************************************
 * ADD SCORE TO GAME
 ***************************************************************************/

cmd_add_score(FILE * outstream, const char ** args)
{
}

/****************************************************************************
 * REPORT
 ***************************************************************************/

cmd_report(FILE * outstream, const char ** args)
{
}

result_t cmd_report_popular(FILE * outstream, const char ** args)
{
}

result_t cmd_report_bestplayer(FILE * outstream, const char ** args)
{
}

result_t cmd_report_notused(FILE * outstream, const char ** args)
{
}
